<template>
	<view style="display: flex;flex-direction: column;justify-content: space-around;height: 50vh;" v-if="isno">
		<u-button type="primary" @click="one">全部订单</u-button>
		<u-button type="primary" @click="one1">产品</u-button>
		<u-button type="primary" @click="one2">计划书</u-button>
		<!-- <u-tabbar v-model="current" :list="list" @change="change"></u-tabbar> -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				isno: false,
				url: '',
				urls: '',
				wxcode: '',
				list: [
					{
						iconPath: "shopping-cart",
						selectedIconPath: "shopping-cart-fill",
						text: '全部订单',
						customIcon: false,
					},
					{
						iconPath: "home",
						selectedIconPath: "home-fill",
						text: '产品',
						customIcon: false,
					},
					{
						iconPath: "play-right",
						selectedIconPath: "play-right-fill",
						text: '计划书',
						customIcon: false,
					}
				],
				current: 0
			}
		},
		mounted() {
			if (!uni.getStorageSync('user_id')) {
				this.wxcode = this.getcode('code')
				this.getOpenid()
			} else {
				this.geturl()
			}
		},
		methods: {
			change (e) {
				// console.log(e + 1)
				// var url = this.url
				// if (e == 0) {
				// 	this.urls = url + '&type=' + 1
				// } else if (e == 1) {
				// 	this.urls = url + '&type=' + 2
				// }   else if (e == 2) {
				// 	// this.urls = url + '&type=' + 3
				// 	window.open(url + '&type=' + 3)
				// 	// window.location.href = url + '&type=' + 3
				// }
				// console.log(this.urls)
			},
			one () {
				var url = this.url
				window.open(url + '&type=' + 1)
			},
			one1 () {
				var url = this.url
				window.open(url + '&type=' + 2)
			},
			one2 () {
				var url = this.url
				window.open(url + '&type=' + 3)
			},
			// 获取微信openid
			getOpenid() {
				var param = {
					code: this.wxcode
				}
				this.$request('', '/api/apiminiapp/login', 'POST', param, {}).then(res => {
					var openid = res.data.wechat_user.openid
					uni.setStorageSync('user_id', res.data.wechat_user.user_id)
					uni.setStorageSync('openid', openid)
					uni.setStorageSync('wechat_user', 1)
					this.geturl(res.data.wechat_user.user_id)
				})
			},
			getcode(name) {
				var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
				var r = window.location.search.substr(1).match(reg);
				if (r != null) return unescape(r[2]);
				return null;
			},
			geturl() {
				var param = {
					user_id: uni.getStorageSync('user_id')
				}
				this.$request('', '/api/apiminiapp/getfxlogin', 'POST', param, {}).then(res => {
					this.url = res.data.data
					this.urls = res.data.data + '&type=' + 1
					this.isno = true
				})
			}
		}
	}
</script>

<style>
</style>
